import pygame

class Beam(pygame.sprite.Sprite):
    duration = 0
    
    def __init__(self, tower, target, duration):
        pygame.sprite.Sprite.__init__(self) 
    
        self.tower = tower
        self.target = target
        self.duration = duration

    def update(self):
        self.duration -= 1
        if self.duration <= 0:
            self.kill()
            self.tower.on_hit(self.target)
        if self.target.health <= 0:
            self.kill()
    
    def draw(self, screen):
        pygame.draw.line(screen, (0,255,0), \
        (self.tower.rect.centerx, self.tower.rect.centery), \
        (self.target.rect.centerx, self.target.rect.centery), 2)